﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Password_Generator
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Random rnd = new Random(); int[] symb = { 33, 35, 36, 37, 38, 42, 95 }; int length;
        private void button2_Click(object sender, EventArgs e)
        {
            StringWriter sw = new StringWriter(); length = Convert.ToInt32(textBox1.Text);
            for (; length > 0; length--)
            {
                switch (rnd.Next(1, 5))
                {
                    case 1: sw.Write((char)rnd.Next(65, 91)); break;
                    case 2: sw.Write((char)rnd.Next(97, 123)); break;
                    case 3: sw.Write((char)rnd.Next(48, 58)); break;
                    case 4: sw.Write((char)symb[rnd.Next(0, 7)]); break;
                }
            }
            textBox2.Text = sw.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Clipboard.SetText(textBox2.Text);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Help help = new Help();
            help.Show();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string file_name = "C:/LastKey.txt";

            System.IO.StreamReader objReader;
            objReader = new System.IO.StreamReader(file_name);

            textBox2.Text = objReader.ReadToEnd();

            objReader.Close();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            File.WriteAllText("C:/LastKey.txt", textBox2.Text);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            File.Delete("C:/LastKey.txt");
            textBox2.Clear();
        }
    }
}
